import React, { Component } from 'react'
import { NameContext } from '../NameContext';
console.log(NameContext);

class Son extends Component {
    UNSAFE_componentWillReceiveProps(props) {
        console.log('props改变后的值为', props);
    }
    componentWillUnmount() {
        console.log('子组件销毁');
    }
    render() {
        return (
            <NameContext.Consumer>
                {({ name, add }) => {
                    return (
                        <div>
                            <div>{name}</div>
                            <div>{this.props.num}</div>
                            <button onClick={() => {
                                add(++name)
                            }}>+</button>
                        </div>

                    )
                }}
            </NameContext.Consumer>

        );
    }
}

export default Son;